package com.yyj.common;

import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.PathMatchConfigurer;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import javax.annotation.Resource;

@Configuration
public class WebConfig implements WebMvcConfigurer {
    @Override
    public void configurePathMatch(PathMatchConfigurer configurer) {
        //在存在RestController或Controller注解的类的请求路径添加统一前缀
        configurer.addPathPrefix("/yyj",
                clazz->clazz.isAnnotationPresent(RestController.class)||clazz.isAnnotationPresent(Controller.class));
    }
    @Resource
    private JwtInterceptor jwtInterceptor;

    // 加自定义拦截器JwtInterceptor，设置拦截规则
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(jwtInterceptor).addPathPatterns("/yyj/**")
                .excludePathPatterns("/yyj/admin/login")
                .excludePathPatterns("/yyj/user/**")
                .excludePathPatterns("/yyj/Cat/**")
                .excludePathPatterns("/yyj/doctor/**")
                .excludePathPatterns("/yyj/files/**")
                .excludePathPatterns("/yyj/audit/**")
                .excludePathPatterns("/yyj/audits/**")
                .excludePathPatterns("/yyj/delete/**")
                .excludePathPatterns("/yyj/reserve/**")
                .excludePathPatterns("/yyj/employee/**")
                .excludePathPatterns("/yyj/calendar/**")
                .excludePathPatterns("/yyj/pet/**")
                .excludePathPatterns("/yyj/rescue/**");
    }

}
